/**
 * @author harae Feng 
 * @date 2019-09-24 15:41:35 
 * @Last Modified by: harae Feng
 * @Last Modified time: 2019-10-18 17:11:39
 * @Describe 抖音-Dou听音乐榜往期周期查询
 */


const fetch = require('../../util/fetchUtil').fetchRequest
const ResultAPI = require('../../routes/api/resultAPI')
const CatchHandle = require('../../routes/api/apicatch')


/**
 * Dou听音乐榜往期周期查询
 */
async function starDouCycle(options){
    let url = `https://api-hl.amemv.com/aweme/v1/hotsearch/branch_billboard/weekly/list/?version_code=${options.version_code}&pass-region=${options['pass-region']}&pass-route=${options['pass-route']}&js_sdk_version=${options.js_sdk_version}&app_name=${options.app_name}&vid=${options.vid}&app_version=${options.app_version}&device_id=${options.device_id}&channel=${options.channel}&mcc_mnc=${options.mcc_mnc}&aid=${options.aid}&screen_width=${options.screen_width}&openudid=${options.openudid}&os_api=${options.os_api}&ac=${options.ac}&os_version=${options.os_version}&device_platform=${options.device_platform}&build_number=${options.build_number}&device_type=${options.device_type}&iid=${options.iid}&idfa=${options.idfa}&type=${options.type || 1}&request_tag_from=${options.request_tag_from}`
    let res = await fetch(url)
    let resJSON = await res.json()
    return resJSON
}

async function starDouCycleAPI(ctx){
    try {
        let parms = ctx.query.parms || {}
        let __Options = Object.assign(parms, require('./__parms.js'))
        let resJSON = await starDouCycle(__Options)
        if(resJSON.status_code === 0){
            return new ResultAPI(0, {}, resJSON)
        }else{
            return new ResultAPI(10003, {}, resJSON)
        }       
    } catch (error) {
        return CatchHandle(__dirname, __filename, error)
    }
}

module.exports = {
    starDouCycleAPI: starDouCycleAPI
}